/**
 * Created by zheng on 2018/7/2.
 */
$(function () {
    $("#pay_datagrid").datagrid({
        url: '/paymentHandling/list',
        fit: true,
        fitColumns: true,
        //分页条
        pagination: true,
        // fit:true,
        //工具栏
        toolbar: "#tb",
        //单选
        singleSelect:true,
        columns: [
          [
            {field: 'x', checkbox: 'true'},
            {field: 'id', title: '编码', width: 100,hidden:true},
            {field: 'oddNumber', title: '保险单号', width: 100},
            {field: 'applicant', title: '投保人', width: 100,formatter:function (v,r,i) {
                    return v? v.name:''
                }},
            {field: 'totalPrice', title: '需缴纳费用', width: 100},
            {field: 'limitYear', title: '保险年限', width: 100},
            {field: 'auditDate', title: '核保日期', width: 100},
            {field: 'organization', title: '保险机构', width: 100,formatter:function (v,r,i) {
                    return v? v.name : ''
                }}
        ]],
        //新增
        border:false,
        cls:"table table-very table-basic"
    })

    $("#productInfo_datagrid").datagrid({
        width:300,
        height:150,
        columns:[[
            {field:'xx',checkbox:true,width:125},
            {field:'name',title:'险种',width:125},
            {field:'annualfee',title:'险种金额',width:125}
        ]]

    })

    //将工具栏所有的函数集合在一个对象中
    var cmdObj;
    cmdObj = {
        //刷新emp页面
        reload: function () {
            $('#pay_datagrid').datagrid("load")
        }
        ,
        //高级查询
        query: function () {
            var keyword = $("#keyword").textbox("getValue");
            $('#pay_datagrid').datagrid('load', {
                keyword: keyword,
            });
        },
        //关闭按钮
        cancel: function () {
            $('#dg').dialog("close")
        },
        add:function () {
            var row = $("#pay_datagrid").datagrid("getSelected");
            console.log(row.totalPrice);
            if(!row){
                $.messager.alert('温馨提示','请选择需要缴费的保单数据');
                return;
            }
            $("#dg").dialog({
                width:400,
                height:600,
                title:'缴费',
                buttons:"#toolb"
            })
            $("#productInfo_datagrid").datagrid('options').url = '/product/queryProductListByBillId?billId='+row.id;
            $("#productInfo_datagrid").datagrid('reload');
            //回显
            $("#appName").textbox("setValue",row.applicant.name)
            $("#orgName").textbox("setValue",row.organization.name)
            $("#oddNumber").textbox("setValue",row.oddNumber)
            $("#ff").form("load",row);
        },
        pay:function () {
            $("#ff").form("submit",{
                url:'/paymentHandling/pay',
                success:function (data) {
                    console.log(data);
                    data=$.parseJSON(data);
                    if(data.succeed){
                      $("#dg").dialog('close');
                      $("#pay_datagrid").datagrid('reload');
                  }else {
                      $.messager.alert('温馨提示',data.errorMsg);
                  }
                },
                onSubmit:function (param) {
                    var row  = $("#pay_datagrid").datagrid("getSelected");
                    console.log(row.applicant.id);
                    param["limitYear"]=row.limitYear;
                    param["applicant.id"]=row.applicant.id;
                }
            })
        }
    }
    //调用函数集合对象
    $("a[data-cmd]").click(function () {
        var cmd = $(this).data("cmd");
        cmdObj[cmd]();
    })
})




